/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package databaseproject;

/**
 *
 * @author Michael DiTraglia
 */
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;

public class Venue {
    
    private static Connection con;
    private static String username;
    private static boolean userIsAdmin;
    
    public static void doMenu(Connection nCon, String nUsername, boolean nUserIsAdmin)
    {
        con = nCon;
        username = nUsername;
        userIsAdmin = nUserIsAdmin;
        
        boolean done = false;

        while (!done)
        {
            Menu menu = new Menu();
            menu.setTitle("Venue");
            menu.addOption("List Venues");
            if (userIsAdmin)
            {
                menu.addOption("Add Venue");
                
            }
            switch (menu.display())
            {
                case (1):
                    Menu listMenu = new Menu();
                    listMenu.addOptionsFromSQLQuery(con, "select vname from VENUE");
                    int choice = listMenu.display();
                    displayDetail(listMenu.getOptionAt(choice));
                    break;
                    
                case (2):
                    if(!userIsAdmin){
                        done = true;
                        break;
                    }
                    
                    Scanner input = new Scanner(System.in);
                    System.out.print("Address: ");
                    String address = input.nextLine();
                    System.out.print("City: ");
                    String city = input.nextLine();
                    System.out.print("State: ");
                    String state = input.nextLine();
                    System.out.print("Venue Name: ");
                    String vName = input.nextLine();
                    
                        try
                        {
                            Statement st = con.createStatement();
                            st.executeUpdate("insert into VENUE values ('"+address+"','"+city+"','"+state+"', '"+vName+"')");
                        }
                        catch (java.sql.SQLException e)
                        {
                            System.out.println("SQL failed in adding venue." + e);
                        }
                    }
                   done = true;
                   break;
        }
    }
    
    public static void displayDetail(String selection)
    
    {
        try
        {
            Statement stmt = con.createStatement(
                                        ResultSet.TYPE_SCROLL_INSENSITIVE,
                                        ResultSet.CONCUR_READ_ONLY);
            ResultSet rs = stmt.executeQuery("select * from VENUE where vname ='" + selection + "'");


            rs.first();
            
            System.out.printf("Address: %s\n",rs.getString("ADDRESS"));
            System.out.printf("City: %s\n",rs.getString("CITY"));
            System.out.printf("State: %s\n",rs.getString("ST"));
            System.out.printf("Venue Name: %s\n",rs.getString("VNAME"));
            
        }
          
        catch (java.sql.SQLException e)
        {
            return;
        }
        
    }
}
